package Demo2;

//定义一个学生类
public class Student implements Comparable<Student>{

    //属性
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    //重写：使用age比较
//   @Override
//    public int compareTo(Student o){
//
//        return this.age - o.age;
//   }

    //重写：使用name比较
    @Override
    public int compareTo(Student o){
        return this.name.compareTo(o.name);
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
